#ifndef __MVP_ALARM_H__
#define __MVP_ALARM_H__

#include "mvdef.h"

#if __cplusplus
extern "C" {
#endif
#ifndef MV_ALARM_AREA_NUM_MAX
#define MV_ALARM_AREA_NUM_MAX		64		/* 报警检测区域块数量上限 */
#endif
typedef enum _alarm_type
{
    ALARM_INVALID     = 0,
    ALARM_PIR_DET     = 1,
    ALARM_MOVE_DET    = 2,
    ALARM_PERSON_DET  = 3,
    ALARM_HUMAN_DET   = ALARM_PERSON_DET,
    ALARM_SMOKE_DET   = 4,
    ALARM_CAR_DET     = 5,
    ALARM_PET_DET     = 6,
    ALARM_BABYCRY_DET = 7,
    ALARM_TYPE_MAX,
}MVP_ALARM_TYPE_E;

typedef struct _mv_rect{
    mv_s32_t width;
    mv_s32_t height;
    struct {
        mv_s32_t x,y;
    }Point;
}Rect;

// 报警物体最大个数
#define ALARM_OBJ_NUM_MAX  48

typedef struct _obj_rect
{
    mv_s32_t x_start;
    mv_s32_t x_end;
    mv_s32_t y_start;
    mv_s32_t y_end;
}OBJ_RECT_T;

typedef struct _mvp_alarm_sound_data
{
    mv_u32_t u32_db_val;
    
}MVP_ALARM_SOUND_DATA_T;

typedef struct _mvp_alarm_image_data
{
    ///< 检测帧ID（用于判断不同类型是否同一帧数据的结果）
    mv_u32_t         u32_frame_id;

    ///< 人形、移动侦测报警
    mv_s32_t         s32_obj_num;
    mv_s32_t         s32_score[ALARM_OBJ_NUM_MAX];
    OBJ_RECT_T       stru_rect[ALARM_OBJ_NUM_MAX];
    ///< 低电量报警
    mv_s32_t         s32_battery_val;
}MVP_ALARM_IMAGE_DATA_T;

typedef struct _mvp_alarm_data
{
    ///< 报警类型
    MVP_ALARM_TYPE_E type;
    ///< PIR 报警
    mv_time_t        alarm_ts_s;
    union{
        MVP_ALARM_SOUND_DATA_T sound_data;
        MVP_ALARM_IMAGE_DATA_T image_data;
    }data;
}MVP_ALARM_DATA_T;

typedef struct _mvp_alarm_info
{
    mv_bool_t        bl_push_data;      ///< 是否推入数据至触发器
    mv_s32_t         s32_sensitivity;   ///< 灵敏度设置 [1-100]

    union _valid_area {                 ///< 报警区域设置,使用数组
        Rect    stru_rect;
        mv_v8_t av8_array[MV_ALARM_AREA_NUM_MAX];
    }valid_area;
         
    MVP_ALARM_TYPE_E type;              ///< 侦测类型
}MVP_ALARM_INFO_T;

/**
 * @brief 开启报警侦测
 * @param info  [in] MVP_ALARM_INFO_T *
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : MV_EC_FAILED
 */
mv_s32_t mvp_alarm_start(MVP_ALARM_INFO_T* info);

/**
 * @brief 停止报警侦测
 * @param type  [in] MVP_ALARM_TYPE_E
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : MV_EC_FAILED
 */
mv_s32_t mvp_alarm_stop(MVP_ALARM_TYPE_E type);

/**
 * @brief 等待侦测数据
 * @param data        [out] MVP_ALARM_DATA_T *
 * @param timeout_ms  [in] mv_s32_t
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : MV_EC_FAILED
 */
mv_s32_t mvp_alarm_wait_trigger (MVP_ALARM_DATA_T *data, mv_s32_t timeout_ms);

/**
 * @brief 侦测数据触发器
 * @param data        [in] MVP_ALARM_DATA_T *
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : MV_EC_FAILED
 */
mv_s32_t mvp_alarm_event_trigger(MVP_ALARM_DATA_T *data);

/**
 * @brief 暂停将数据推入触发器
 * @param type  [in] MVP_ALARM_TYPE_E
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : MV_EC_FAILED
 */
mv_s32_t mvp_alarm_pause (MVP_ALARM_TYPE_E type);

/**
 * @brief 恢复将数据推入触发器
 * @param type  [in] MVP_ALARM_TYPE_E
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : MV_EC_FAILED
 */
mv_s32_t mvp_alarm_resume(MVP_ALARM_TYPE_E type);

mv_s32_t mvp_alarm_sensitivity_set(MVP_ALARM_TYPE_E type, mv_s32_t s32_sensitivity);
mv_s32_t mvp_alarm_sensitivity_get(MVP_ALARM_TYPE_E type);

mv_s32_t mvp_alarm_light_sen_framecnt2level(MVP_ALARM_TYPE_E type, mv_s32_t frame_cnt);
mv_s32_t mvp_alarm_light_sen_level2framecnt(MVP_ALARM_TYPE_E type, mv_s32_t level);

/**
 * @brief 报警画框接口
 * @param data       [in] MVP_ALARM_DATA_T * 报警数据
 * @param frame_num  [in] mv_s32_t           画框帧数
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : MV_EC_FAILED
 */
mv_s32_t mvp_alarm_draw_box(MVP_ALARM_DATA_T *data);

#if __cplusplus
}
#endif

#endif